package com.guozcc.gateway.autofilter.base;

import org.reactivestreams.Publisher;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.gateway.filter.factory.rewrite.RewriteFunction;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;


/**
 * 操作请求or响应报文
 */
public class BodyRewriteImpl implements RewriteFunction<byte[], byte[]> {
    private final Logger log = LoggerFactory.getLogger(this.getClass());
    @Override
    public Publisher<byte[]> apply(ServerWebExchange serverWebExchange, byte[] bytes) {
        try {
            String msg = new String(bytes, "UTF-8");
            log.info("报文："+msg);
        } catch (Exception ex) {
            log.error("1. json process fail", ex);
        }
        return Mono.just(bytes);
    }
}
